package edu.xupt.ediction.slice;

import edu.xust.ediction.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.Text;

import java.util.ArrayList;

public class WearableSearchResultAbilitySlice extends AbilitySlice {
    private Text textSearchResult;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_search_result);
        //设置按钮跳转到设置界面
        Image result_return=(Image)this.findComponentById(ResourceTable.Id_result_return);
        result_return.setClickedListener(component ->present(new SearchAbilitySlice(),new Intent()));

        textSearchResult = (Text)findComponentById(ResourceTable.Id_text_search_result);
        if(textSearchResult != null) {
            textSearchResult.setText("");
            ArrayList<String> typeList = intent.getStringArrayListParam("typeList");
            ArrayList<String> meaningList = intent.getStringArrayListParam("meaningList");
            for(int i = 0; i < typeList.size();i++) {
                textSearchResult.append(typeList.get(i) + " " + meaningList.get(i) + "\r\n") ;
            }
            if(typeList.size() == 0) {
                textSearchResult.setText("单词没有查到，请确认单词是否输入错误！");
            }
        }
    }
}
